package com.zmn.plat.common.dictionary;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 收尾款方
 *
 * @author yangshuangping
 * @since 2021-7-1 18:07:
 */
public enum ChannelSettlePayerEnum {

    /**
     * values
     */
    ZMN(ChannelSettlePayerEnum.CONSTS_CHANNEL, "啄木鸟"),
    CHANNEL(ChannelSettlePayerEnum.CONSTS_CUSTOMER, "渠道方"),
    ;

    /**
     * 收尾款方：1.啄木鸟
     */
    public final static int CONSTS_CHANNEL = 1;
    /**
     * 收尾款方：2.渠道方
     */
    public final static int CONSTS_CUSTOMER = 2;

    private Integer code;
    private String name;

    ChannelSettlePayerEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static String getName(Integer code) {
        ChannelSettlePayerEnum of = of(code);
        return of == null ? null : of.getName();
    }

    public static ChannelSettlePayerEnum of(Integer code) {
        switch (code) {
            case 1:
                return ZMN;
            case 2:
                return CHANNEL;
            default:
                return null;
        }
    }

    public static String getIncludeName(String code) {
        String[] codes = code.split(",", -1);
        List<String> list = new ArrayList<>();
        Arrays.stream(codes).forEach(x -> {
            ChannelSettlePayerEnum of = of(Integer.parseInt(x));
            if (null != of) {
                list.add(of.getName());
            }
        });
        return String.join(",", list);
    }
}
